package com.webex.ta.hydra.gui.action;

import com.webex.ta.hydra.clipboard.ClipBoard;
import com.webex.ta.hydra.core.Command;
import com.webex.ta.hydra.gui.GuiPackage;
import com.webex.ta.hydra.gui.table.HydraTableModel;

import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-7
 * Time: 9:00:49
 */
public class CopyCommandAction implements ActionHandler {
    private static Set<String> commands = new HashSet<String>();

    static {
        commands.add(ActionNames.COPY_LINE);
    }

    public Set<String> getActionNames() {
        return commands;
    }

    public void doAction(ActionEvent e) {
        GuiPackage gp = GuiPackage.getInstance();
        int[] rows = gp.getHydraTable().getSelectedRows();
        if (rows.length > 0) {
            HydraTableModel tableModel = gp.getHydraTable().getModel();
            Command[] commands = new Command[rows.length];
            for (int i = 0; i < rows.length; i++) {
                commands[i] = tableModel.getCommandAt(rows[i]);
            }
            ClipBoard.getInstance().setContents(commands);
            gp.updateMenuAndToolBar();
        }
    }
}
